﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace DBMS.Models
{
    public class Database
    {
        public Database()
        {
            Tables = new List<Table>();
        }
        public int Index { get; set; }

        [Required]
        [Display(Name = "Database Name")]
        public string Name { get; set; }

        public IList<Table> Tables { get; set; }

        public bool Deleted { get; set; }

        public Table GetTableByName(String tableName)
        {
            foreach (Table table in Tables)
            {
                if (table.Name.Equals(tableName))
                {
                    return table;
                }
            }
            return null;
        }

        public Table GetTableByIndex(int tableIndex)
        {
            foreach (Table table in Tables)
            {
                if (table.Index == tableIndex)
                {
                    return table;
                }
            }
            return null;
        }
    }
}
